import 'package:environmental_les_app/common/net/net.dart';
import 'package:environmental_les_app/common/utils.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
import 'package:flutter_clx_base/widget/base_list_widget.dart';

class TaskListController extends GetxController {
  TaskListController();

  //当前时间筛选结果
  Map<String, dynamic> allTime = {};

  // 当前选中的筛选项，prop -> list of selected values
  final Map<String, List<String>> selectedFilters = {};

  // 筛选项
  final List<Map<String, dynamic>> filterData = [
    {
      "title": "任务类型",
      "prop": "siteType",
      "multiSelect": false,
      "filter": [
        {"name": "日常任务", "value": "1"},
        {"name": "临时任务", "value": "2"},
      ],
    },
    {
      "title": "任务状态",
      "prop": "alarmType",
      "multiSelect": false,
      "filter": [
        {"name": "未开始", "value": "1"},
        {"name": "进行中", "value": "2"},
        {"name": "已完成", "value": "3"},
      ],
    },
    {
      "title": "是否督办",
      "prop": "status",
      "multiSelect": true,
      "filter": [
        {"name": "是", "value": "1"},
        {"name": "否", "value": "2"},
      ],
    },
  ];

  final listController = BaseListController();

  // 更新选中结果（来自弹窗返回）
  void updateSelection(Map<String, dynamic>? result) {
    updateSelectedFilters(selectedFilters, filterData, result);
    update(["warning_list"]);
  }

  _initData() {
    update(["task_list"]);
  }

  void getList(page, pageSize, success, error) {
    DioUtils.instance.getMockAdapter().onGet(
          ServiceApi.taskList,
          (server) => server.reply(
              200,
              {
                "data": {
                  "records": List.generate(5, (index) {
                    return {
                      "title": "标题 $index",
                      "subtitle": "这是第 $index 条数据",
                    };
                  }),
                },
                "msg": "success",
                "code": 0
              },
              delay: const Duration(seconds: 1)),
        );

    NetUtils.get(ServiceApi.taskList, queryParameters: null,
        successCallback: (data) {
      success(data['records']);
    }, errorCallback: error);
  }

  void onTap() {}

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
